const fs = require('fs');
// 读取fs模块

// fs.readFile('./resource/content.txt',(err,data) => {
//     //如果出错则抛出错误
//     if (err) throw err;
//     //输出文件内容
//     console.log(data.toString());
// });


// promise实现
const p = new Promise((resolve, reject) => {
    fs.readFile('./resource/content.txt', (err, data) => {
        //如果失败
        if (err) reject(err);
        //如果成功
        resolve(data);
    })
});
//3. 调用then方法 
p.then(value => console.log(value.toString())
    , reason => console.log(reason)
)

